home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / basic / qbnws201.zip / Z.BAS < prev   
BASIC Source File  |  1991-01-08  |  19KB  |  342 lines

  1. REM Z.BAS Copyright 1990
  2. REM by Charles Graham, POB 58634, St. Louis, MO 63158
  3. '                                                      
  4. 'Z.BAS is an elementary communications program written in
  5. 'Microsoft QuickBASIC 4.5.  It opens the computer's console
  6. '(CON) as a file and funnels all screen writes through CON.
  7. 'If a user has ANSI.SYS installed properly, this technique
  8. 'makes Z.BAS compatible with Bulletin Board Systems that use
  9. 'ANSI escape sequences to produce color and animation on their
  10. 'user's screens.                                           
  11. '                                                      
  12. 'There are only a few requirements for running Z.BAS:  
  13. '   1)  use an IBM-compatible computer with at least   
  14. '       128K of available RAM                          
  15. '   2)  use a Hayes-compatible modem                   
  16. '   3)  use a color monitor and video board            
  17. '   4)  call a BBS using modem parameters of N,8,1 (no 
  18. '       parity, 8 data bits, 1 stop bit) unless you want
  19. '       to change the code in SUB getparms             
  20. '   5)  install ANSI.SYS if not already installed.     
  21. '
  22. DECLARE SUB bottomline ()                   'Prints line 25
  23. DECLARE SUB delay ()                        'Wastes time
  24. DECLARE SUB getparms ()                     'You need these
  25. DECLARE SUB hangup ()                       'Byebye, BBS
  26. DECLARE SUB initialize ()                   'Foreplay
  27. DECLARE SUB makeacall ()                    'Reach out & touch
  28. DECLARE SUB opencomport ()                  'Open Sesame
  29. DECLARE SUB outtahere ()                    'I quit!
  30.                                             '
  31. DIM SHARED ao$                              'Lots of SUBs
  32. DIM SHARED cs$                              ' need these so
  33. DIM SHARED bp$                              ' SHARE
  34. DIM SHARED comport$                         '
  35. DIM SHARED comspec$                         '
  36. DIM SHARED es$                              '
  37. DIM SHARED dialmode$                        '
  38. DIM SHARED firsttime$                       '
  39. DIM SHARED init$                            '
  40. DIM SHARED hc$                              '
  41. ON ERROR GOTO errorroutine                  'Just in case
  42. DEFINT A-Z                                  'Speeds things up
  43. es$ = CHR$(27)                              'ESCape
  44. ao$ = es$ + "[0m"                           'Attributes off
  45. cs$ = es$ + "[2J"                           'Clear screen
  46. f1$ = CHR$(0) + CHR$(59)                    'F1 key
  47. f10$ = CHR$(0) + CHR$(68)                   'F10 key
  48. ff$ = CHR$(12)                              'Form feed
  49. hc$ = es$ + "[f"                            'Home cursor
  50. OPEN "con" FOR OUTPUT AS 2                  'Console as file
  51. CALL initialize                             'Foreplay
  52. PRINT #2, ao$;                              'Attributes off
  53. PRINT #2, cs$ + " " + hc$;                  'Home cursor
  54. CALL getparms                               'You need these
  55. CALL opencomport                            'Open Sesame
  56. CALL bottomline                             'Print line 25
  57. DO                                          'Begin endless loop
  58.     a$ = INKEY$                             'Check keyboard
  59.     IF a$ <> "" THEN                        'Key pressed?
  60.         SELECT CASE a$                      'What do I do now?
  61.             CASE es$                        'ESCape key?
  62.                 CALL hangup                 ' Byebye, BBS
  63.             CASE f1$                        'F1 key?
  64.                 CALL makeacall              ' Reach out & touch
  65.             CASE f10$                       'F10 key?
  66.                 CALL outtahere              ' I quit!
  67.             CASE ELSE                       'Some other key?
  68.                 PRINT #1, a$;               ' Send it to modem
  69.         END SELECT                          '
  70.     END IF                                  '
  71.     WHILE NOT EOF(1)                        'Characters arrived?
  72.         b$ = INPUT$(LOC(1), #1)             'Receive characters
  73.         WHILE INSTR(b$, ff$) <> 0           'If an ASCII form
  74.             q = INSTR(b$, ff$)              ' feed is received
  75.             b$ = LEFT$(b$, q - 1) + cs$ + MID$(b$, q + 1)
  76.                                             ' change it to ANSI
  77.         WEND                                '
  78.         PRINT #2, b$;                       'Print characters
  79.         a$ = INKEY$                         'Check keyboard
  80.         IF a$ <> "" THEN                    'Key pressed?
  81.             SELECT CASE a$                  'What do I do now?
  82.                 CASE es$                    'ESCape key?
  83.                     CALL hangup             ' Byebye, BBS
  84.                 CASE f1$                    'F1 key?
  85.                     CALL makeacall          ' Reach out & touch
  86.                 CASE f10$                   'F10 key?
  87.                     CALL outtahere          ' I quit!
  88.                 CASE ELSE                   'Some other key?
  89.                     PRINT #1, a$;           ' Send it to modem
  90.             END SELECT                      '
  91.         END IF                              '
  92.     WEND                                    '
  93. LOOP                                        'End endless loop
  94.                                             '
  95. errorroutine:                               'Who knows what evil
  96. PRINT "Error type"; ERR; "occurred!"        'lurks within the
  97. RESUME NEXT                                 'hearts of computers?
  98.  
  99. SUB bottomline                              'Prints line 25
  100. PRINT #2, cs$;                              'Clear screen
  101. PRINT #2, es$ + "[25;1f";                   'LOCATE 25, 1
  102. PRINT #2, es$ + "[1;37;44m";                'Bright white on blue
  103. PRINT #2, "Z QB Dialer  Copr. 1990 by Charles Graham   ";
  104. PRINT #2, es$ + "[1;33m";                   'Yellow on blue
  105. PRINT #2, "  ESC Hang Up    F1 Dial    F10 End";
  106. PRINT #2, ao$;                              'Attributes off
  107. PRINT #2, hc$ + " " + hc$;                  'Home cursor
  108. END SUB                                     '
  109.  
  110. SUB delay                                   'Wastes time
  111. now! = TIMER                                '"now!" needs to be
  112. WHILE TIMER - now! < 1.5                    ' a SINGLE precision
  113. WEND                                        ' variable
  114. END SUB                                     '
  115.  
  116. SUB getparms                                'You need these
  117. PRINT #2, cs$;                              'Clear screen
  118. IF firsttime$ = "on" THEN                   'Skip this if it's
  119.     firsttime$ = "off"                      ' your first call;
  120. ELSE                                        ' otherwise:
  121.     PRINT #2, es$ + "[1;36m";               'Light cyan
  122.     PRINT #2, hc$;                          'Home cursor
  123.     PRINT #2, "Modem speed ";               'Prompt for bps
  124.     PRINT #2, es$ + "[1;33m";               'Yellow
  125.     PRINT #2, "3";                          '
  126.     PRINT #2, es$ + "[1;36m";               'Light cyan
  127.     PRINT #2, "00 ";                        '
  128.     PRINT #2, es$ + "[1;33m";               'Yellow
  129.     PRINT #2, "1";                          '
  130.     PRINT #2, es$ + "[1;36m";               'Light cyan
  131.     PRINT #2, "200 ";                       '
  132.     PRINT #2, es$ + "[1;33m";               'Yellow
  133.     PRINT #2, "2";                          '
  134.     PRINT #2, es$ + "[1;36m";               'Light cyan
  135.     PRINT #2, "400 ";                       '
  136.     PRINT #2, es$ + "[1;33m";               'Yellow
  137.     PRINT #2, "9";                          '
  138.     PRINT #2, es$ + "[1;36m";               'Light cyan
  139.     PRINT #2, "600 [";                      '
  140.     PRINT #2, es$ + "[1;33m";               'Yellow
  141.     PRINT #2, "1";                          '
  142.     PRINT #2, es$ + "[1;36m";               'Light cyan
  143.     PRINT #2, "/";                          '
  144.     PRINT #2, es$ + "[1;33m";               'Yellow
  145.     PRINT #2, "2";                          '
  146.     PRINT #2, es$ + "[1;36m";               'Light cyan
  147.     PRINT #2, "/";                          '
  148.     PRINT #2, es$ + "[1;33m";               'Yellow
  149.     PRINT #2, "3";                          '
  150.     PRINT #2, es$ + "[1;36m";               'Light cyan
  151.     PRINT #2, "/";                          '
  152.     PRINT #2, es$ + "[1;33m";               'Yellow
  153.     PRINT #2, "9";                          '
  154.     PRINT #2, es$ + "[1;36m";               'Light cyan
  155.     PRINT #2, "]? ";                        '
  156.     PRINT #2, es$ + "[1;33m";               'Yellow
  157.     bp$ = ""                                'Initialize to null
  158.     WHILE bp$ <> "1" AND bp$ <> "2" AND bp$ <> "3" AND bp$ <> "9"
  159.         bp$ = INKEY$                        'Wait for 1, 2, 3
  160.     WEND                                    ' or 9 to be pressed
  161.     comspec$ = "COM" + comport$ + ":"       'Initialize comspec
  162.     SELECT CASE bp$                         'Whadda we got?
  163.         CASE "1"                            '1 pressed?
  164.             PRINT #2, "1200 bps";           ' Tell user
  165.             comspec$ = comspec$ + "1200"    ' Add 1200 to comspec
  166.         CASE "2"                            '2 pressed?
  167.             PRINT #2, "2400 bps";           ' Tell user
  168.             comspec$ = comspec$ + "2400"    ' Add 2400 to comspec
  169.         CASE "3"                            '3 pressed? 
  170.             PRINT #2, "300 bps";            ' Tell user
  171.             comspec$ = comspec$ + "300"     ' Add 300 to comspec
  172.         CASE "9"                            '9 pressed?
  173.             PRINT #2, "9600 bps";           ' Tell user
  174.             comspec$ = comspec$ + "9600"    ' Add 9600 to comspec
  175.     END SELECT                              '
  176.     comspec$ = comspec$ + ",N,8,1,DS"       'Complete comspec
  177. END IF                                      '
  178. END SUB                                     '
  179.  
  180. SUB hangup                                  'Byebye, BBS
  181. PRINT #2, cs$;                              'Clear screen
  182. PRINT #2, es$ + "[1;5;37;41m";              'Blink white on red
  183. PRINT #2, es$ + "[25;39H";                  'LOCATE 25, 39
  184. PRINT #2, "Wait";                           'Tell user
  185. CALL delay                                  'Waste time
  186. PRINT #1, "+++";                            'Wake up your modem
  187. CALL delay                                  'Waste time
  188. PRINT #1, "ATH0"                            'Tell modem to hangup
  189. PRINT #2, ao$;                              'Attributes off
  190. IF NOT EOF(1) THEN                          'Clear the com buffer
  191.     b$ = INPUT$(LOC(1), #1)                 ' of any unprocessed
  192. END IF                                      ' bytes
  193. CALL bottomline                             'Print line 25
  194. END SUB                                     '
  195.  
  196. SUB initialize                              'Foreplay
  197. PRINT #2, ao$;                              'Attributes off
  198. PRINT #2, cs$;                              'Clear screen
  199. PRINT #2, es$ + "[1;36m";                   'Light cyan
  200. PRINT #2, "Modem initialization string? ";  'Prompt user
  201. PRINT #2, es$ + "[1;33m";                   'Yellow
  202. a$ = ""                                     'Initialize to null
  203. WHILE a$ <> CHR$(13)                        'Until Return pressed
  204.     a$ = INKEY$                             'Grab key pressed
  205.     IF a$ = CHR$(8) AND LEN(init$) THEN     'Backspace?
  206.         PRINT #2, es$ + "[1D";              ' Lop off the right-
  207.         PRINT #2, " ";                      ' most character and
  208.         PRINT #2, es$ + "[1D";              ' move cursor left
  209.         IF LEN(init$) > 1 THEN              ' Truncate init$
  210.             init$ = LEFT$(init$, LEN(init$) - 1)'by one character
  211.         ELSE                                ' or
  212.             init$ = ""                      '  make it null
  213.         END IF                              '
  214.     ELSE                                    '
  215.         a$ = UCASE$(a$)                     'Make it upper case
  216.         IF a$ > " " THEN                    'Reject strange chars
  217.             init$ = init$ + a$              'Add char to init$
  218.             PRINT #2, a$;                   'Print the character
  219.         END IF                              '
  220.     END IF                                  '
  221. WEND                                        '
  222. PRINT #2, cs$;                              'Clear screen
  223. PRINT #2, es$ + "[1;36m";                   'Light cyan
  224. PRINT #2, "Comm Port [";                    'Prompt user
  225. PRINT #2, es$ + "[1;33m";                   'Yellow
  226. PRINT #2, "1";                              '
  227. PRINT #2, es$ + "[1;36m";                   'Light cyan
  228. PRINT #2, "/";                              '
  229. PRINT #2, es$ + "[1;33m";                   'Yellow
  230. PRINT #2, "2";                              '
  231. PRINT #2, es$ + "[1;36m";                   'Light cyan
  232. PRINT #2, "]? ";                            '
  233. PRINT #2, es$ + "[1;33m";                   'Yellow
  234. WHILE comport$ <> "1" AND comport$ <> "2"   'Wait for a 1 or 2
  235.     comport$ = INKEY$                       ' to be pressed
  236. WEND                                        '
  237. PRINT #2, comport$;                         'Tell user
  238. PRINT #2, cs$;                              'Clear screen
  239. PRINT #2, es$ + "[1;36m";                   'Light cyan
  240. PRINT #2, "DIAL ";                          'Prompt user
  241. PRINT #2, es$ + "[1;33m";                   'Yellow
  242. PRINT #2, "P";                              '
  243. PRINT #2, es$ + "[1;36m";                   'Light cyan
  244. PRINT #2, "ulse or ";                       '
  245. PRINT #2, es$ + "[1;33m";                   'Yellow
  246. PRINT #2, "T";                              '
  247. PRINT #2, es$ + "[1;36m";                   'Light cyan
  248. PRINT #2, "one [";                          '
  249. PRINT #2, es$ + "[1;33m";                   'Yellow
  250. PRINT #2, "P";                              '
  251. PRINT #2, es$ + "[1;36m";                   'Light cyan
  252. PRINT #2, "/";                              '
  253. PRINT #2, es$ + "[1;33m";                   'Yellow
  254. PRINT #2, "T";                              '
  255. PRINT #2, es$ + "[1;36m";                   'Light cyan
  256. PRINT #2, "]? ";                            '
  257. WHILE dialmode$ <> "P" AND dialmode$ <> "T" 'Wait for a P or T
  258.     dialmode$ = INKEY$                      ' to be pressed
  259.     dialmode$ = UCASE$(dialmode$)           'Make it upper case
  260. WEND                                        '
  261. PRINT #2, es$ + "[1;33m";                   'Yellow
  262. IF dialmode$ = "P" THEN                     'P pressed?
  263.     PRINT #2, "Pulse";                      ' Print Pulse
  264. ELSE                                        'else
  265.     PRINT #2, "Tone";                       ' Print Tone
  266. END IF                                      '
  267. END SUB                                     '
  268.  
  269. SUB makeacall                               'Reach out & touch
  270. PRINT #2, cs$;                              'Clear screen
  271. PRINT #2, es$ + "[1;5;37;41m";              'Blink white on red
  272. PRINT #2, es$ + "[25;39H";                  'LOCATE 25, 39
  273. PRINT #2, "Wait";                           'Tell user
  274. CALL delay                                  'Waste time
  275. PRINT #1, "+++";                            'Wake up your modem
  276. CALL delay                                  'Waste time
  277. PRINT #1, "ATH0"                            'Tell modem to hangup
  278. PRINT #2, ao$;                              'Attributes off
  279. IF NOT EOF(1) THEN                          'Clear the com buffer
  280.     b$ = INPUT$(LOC(1), #1)                 ' of any unprocessed
  281. END IF                                      ' bytes
  282. CALL getparms                               'You need these
  283. CALL opencomport                            'Open Sesame
  284. PRINT #2, cs$;                              'Clear screen
  285. PRINT #2, es$ + "[1;36m";                   'Light cyan
  286. PRINT #2, "Phone number? ";                 'Prompt user
  287. PRINT #2, es$ + "[1;33m";                   'Yellow
  288. dial$ = ""                                  'Initialize to null
  289. WHILE a$ <> CHR$(13)                        'Until Return pressed
  290.     a$ = INKEY$                             'Grab key pressed
  291.     IF a$ = CHR$(8) AND LEN(dial$) THEN     'Backspace?
  292.         PRINT #2, es$ + "[1D";              ' Lop off the right-
  293.         PRINT #2, " ";                      ' most character and
  294.         PRINT #2, es$ + "[1D";              ' move cursor left
  295.         IF LEN(dial$) > 1 THEN              ' Truncate dial$ by
  296.             dial$ = LEFT$(dial$, LEN(dial$) - 1)'  one character
  297.         ELSE                                ' or
  298.             dial$ = ""                      '  make it null
  299.         END IF                              '
  300.     ELSE                                    '
  301.         a$ = UCASE$(a$)                     'Make it upper case
  302.         IF a$ > " " THEN                    'Reject strange chars
  303.             dial$ = dial$ + a$              'Add char to dial$
  304.             PRINT #2, a$;                   'Print the character
  305.         END IF                              '
  306.     END IF                                  '
  307. WEND                                        '
  308. PRINT #1, "ATD" + dialmode$ + dial$         'Tell modem to dial
  309. PRINT #2, ao$;                              'Attributes off
  310. PRINT #2, cs$ + " " + hc$;                  'Clear screen
  311. END SUB                                     '
  312.  
  313. SUB opencomport                             'Open Sesame
  314. CLOSE #1                                    'Close com port
  315. OPEN comspec$ FOR RANDOM AS 1               'Open com port
  316. IF firsttime$ = "" THEN                     'First time?
  317.     PRINT #1, init$                         ' Send init$ to modem
  318.     firsttime$ = "on"                       ' Remember you did so
  319. END IF                                      '
  320. END SUB                                     '
  321.  
  322. SUB outtahere                               'I quit!
  323. PRINT #2, cs$;                              'Clear screen
  324. PRINT #2, es$ + "[1;5;37;41m";              'Blink white on red
  325. PRINT #2, es$ + "[25;39H";                  'LOCATE 25, 39
  326. PRINT #2, "Wait";                           'Tell user
  327. CALL delay                                  'Waste time
  328. PRINT #1, "+++";                            'Wake up your modem
  329. CALL delay                                  'Waste time
  330. PRINT #1, "ATH0"                            'Tell modem to hangup
  331. IF NOT EOF(1) THEN                          'Clear the com buffer
  332.     b$ = INPUT$(LOC(1), #1)                 ' of any unprocessed
  333. END IF                                      ' bytes
  334. CLOSE #1                                    'Close com port
  335. PRINT #2, ao$;                              'Attributes off
  336. PRINT #2, cs$ + " " + hc$;                  'Clear screen
  337. CLOSE #2                                    'Close "con"
  338. b$ = ""                                     'Make b$ null
  339. END                                         'T-T-That's All Folks
  340. END SUB                                     '
  341.  
  342.